﻿using University.Workshop.Business;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using University.Workshop.Model;
using System.Data;

namespace University.Workshop.Tests
{
    
    
    /// <summary>
    ///This is a test class for UserManagerTest and is intended
    ///to contain all UserManagerTest Unit Tests
    ///</summary>
    [TestClass()]
    public class UserManagerTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        private Manager LoadUser()
        {
            Random random = new Random(DateTime.Now.Millisecond);
            Manager user = new Manager();
            user.CIManager = "44" + random.Next(10000);
            user.FirstName = "Alejandro";
            user.LastName = "Goaita";
            user.Address = "America";
            user.CellPhone = 72434356;
            user.Phone = 4444444;
            user.DateInscription = DateTime.Today;
            user.Email = "alejandro@hotmail.com";
            user.Gender = "Male";
            //user.UserType = "Doctor";
            user.UserName = "Alejandro"+random.Next(1000);
            user.Password = "ale12345";
            user.StateManager = true;
            user.ImageManager = null;
            return user;
        }
        /// <summary>
        ///A test for InsertNewUser
        ///</summary>
        [TestMethod()]
        public void InsertNewUserTest()
        {
            Manager newUser = LoadUser(); ; // TODO: Initialize to an appropriate value
            bool expected = true; // TODO: Initialize to an appropriate value
            bool actual;
            actual = UserManager.InsertNewUser(newUser,"Manager");
            Assert.AreEqual(expected, actual);
            Assert.AreNotEqual(false,null);
            //Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for InsertNewUser Null
        ///</summary>
        [TestMethod()]
        public void InsertNewUserNullTest()
        {
            Manager newUser = null; // TODO: Initialize to an appropriate value
            bool expected = false; // TODO: Initialize to an appropriate value
            bool actual;
            actual = UserManager.InsertNewUser(newUser,"Manager");
            Assert.AreEqual(expected, actual);
            Assert.AreNotEqual(false, null);
            //Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for DisableUser execute consult
        ///</summary>
        [TestMethod()]
        public void DisableUserTest()
        {
            //string idUser = "4494524"; // TODO: Initialize to an appropriate value
            Manager newUser = LoadUser();
            UserManager.InsertNewUser(newUser,"Manager");
            bool expected = true; // TODO: Initialize to an appropriate value
            bool actual;
            actual = UserManager.DisableUser(newUser.CIManager);
            Assert.AreEqual(expected, actual);
            Assert.AreNotEqual(false,null);
            //Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for DisableUser Null execute consult false
        ///</summary>
        [TestMethod()]
        public void DisableUserNullTest()
        {
            //string idUser = "4494524"; // TODO: Initialize to an appropriate value
            string idUser = string.Empty;
            bool expected = false; // TODO: Initialize to an appropriate value
            bool actual;
            actual = UserManager.DisableUser(idUser);
            Assert.AreEqual(expected, actual);
            //Assert.AreNotEqual(false, null);
            //Assert.Inconclusive("Verify the correctness of this test method.");
        }

        ///// <summary>
        /////A test for LoadDataGridViewUser
        /////</summary>
        [TestMethod()]
        public void LoadDataGridViewUserTest()
        {
            //DataTable expected = null; // TODO: Initialize to an appropriate value
            DataTable actual;
            actual = UserManager.LoadDataGridViewUser();
            Assert.IsTrue(actual.Rows.Count >= 1);

            //Assert.AreEqual(expected, actual);
            //Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for ModifyPasswordUser
        ///</summary>
        [TestMethod()]
        public void ModifyPasswordUserTest()
        {
            //Random random = new Random(DateTime.Now.Millisecond);
            string userName = "victor"; // TODO: Initialize to an appropriate value
            string password = "victor123"; // TODO: Initialize to an appropriate value
            string newPassword = "victor123"; // TODO: Initialize to an appropriate value
            bool expected = true; // TODO: Initialize to an appropriate value
            bool actual;
            actual = UserManager.ModifyPasswordUser(userName, password, newPassword);
            Assert.AreEqual(expected, actual);
            
            //Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for ModifyUser
        ///</summary>
        [TestMethod()]
        public void ModifyUserTest()
        {
            //User user = LoadUser(); // TODO: Initialize to an appropriate value
            string idUser = "6588726"; // TODO: Initialize to an appropriate value
            Manager user = new Manager();
            user.CIManager = "6588726";
            user.FirstName = "Alejandro";
            user.LastName = "Goaita";
            user.Address = "America";
            user.CellPhone = 72434356;
            user.Phone = 4444444;
            user.DateInscription = DateTime.Today;
            user.Email = "alejandro@hotmail.com";
            user.Gender = "Male";
            //user.UserType = "Doctor";
            user.UserName = "Alejandro";
            user.Password = "ale12345";
            user.StateManager = true;
            user.ImageManager = null;
            bool expected = true; // TODO: Initialize to an appropriate value
            bool actual;
            actual = UserManager.ModifyUser(user, idUser);
            Assert.AreEqual(expected, actual);
            //Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for ModifyUser null
        ///</summary>
        [TestMethod()]
        public void ModifyUserNullTest()
        {
            //User user = LoadUser(); // TODO: Initialize to an appropriate value
            string idUser = "6588726"; // TODO: Initialize to an appropriate value
            Manager user = new Manager();
            user = null;
            bool expected = false; // TODO: Initialize to an appropriate value
            bool actual;
            actual = UserManager.ModifyUser(user, idUser);
            Assert.AreEqual(expected, actual);
            //Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for UserExists
        ///</summary>
        [TestMethod()]
        public void UserExistsTest()
        {
            string userName = "victor"; // TODO: Initialize to an appropriate value
            bool expected = true; // TODO: Initialize to an appropriate value
            bool actual;
            actual = UserManager.UserExists(userName);
            Assert.AreEqual(expected, actual);
            //Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for ValidateConfirmPassword
        ///</summary>
        [TestMethod()]
        public void ValidateConfirmPasswordTest()
        {
            string password = "victor12345"; // TODO: Initialize to an appropriate value
            string confirmPassword = "victor12345"; // TODO: Initialize to an appropriate value
            bool expected = true; // TODO: Initialize to an appropriate value
            bool actual;
            actual = UserManager.ValidateConfirmPassword(password, confirmPassword);
            Assert.AreEqual(expected, actual);
            //Assert.Inconclusive("Verify the correctness of this test method.");
        }
        /// <summary>
        ///A test for error ValidateConfirmPassword
        ///</summary>
        [TestMethod()]
        public void ErrorValidateConfirmPasswordTest()
        {
            string password = "victor12345"; // TODO: Initialize to an appropriate value
            string confirmPassword = "victor125"; // TODO: Initialize to an appropriate value
            bool expected = false; // TODO: Initialize to an appropriate value
            bool actual;
            actual = UserManager.ValidateConfirmPassword(password, confirmPassword);
            Assert.AreEqual(expected, actual);
            //Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for LogOnUser
        ///</summary>
        [TestMethod()]
        public void LogOnUserTest()
        {
            string userName = "victor"; // TODO: Initialize to an appropriate value
            string password = "victor123"; // TODO: Initialize to an appropriate value
            string[] expected = new string[4]; // TODO: Initialize to an appropriate value
            expected[0] = "Victor Hugo";
            expected[1] = "Peña";
            expected[2] = "victor";
            expected[3] = "6600234";
            string[] actual;
            actual = UserManager.LogOnUser(userName, password);
            Assert.AreEqual(expected[0], actual[0]);
            Assert.AreEqual(expected[1],actual[1]);
            Assert.AreEqual(expected[2],actual[2]);
            Assert.AreEqual(expected[3],actual[3]);
            //Assert.Inconclusive("Verify the correctness of this test method.");
        }
        /// <summary>
        ///A test for ErrorValidatingLogOnUser
        ///</summary>
        [TestMethod()]
        public void ErrorValidatingLogOnUserTest()
        {
            string userName = "victor=+@"; // TODO: Initialize to an appropriate value
            string password = "victor123"; // TODO: Initialize to an appropriate value
            string[] expected = null; // TODO: Initialize to an appropriate value
            string[] actual;
            actual = UserManager.LogOnUser(userName, password);
            Assert.AreEqual(expected, actual);
            //Assert.Inconclusive("Verify the correctness of this test method.");
        }
        /// <summary>
        ///A test for ErrorLogOnUser
        ///</summary>
        [TestMethod()]
        public void ErrorLogOnUserTest()
        {
            string userName = "Manuel"; // TODO: Initialize to an appropriate value
            string password = "manuel123"; // TODO: Initialize to an appropriate value
            string[] expected = null; // TODO: Initialize to an appropriate value
            string[] actual;
            actual = UserManager.LogOnUser(userName, password);
            Assert.AreEqual(expected, actual);
            //Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for ci LoadDataGridViewSearchUser
        ///</summary>
        [TestMethod()]
        public void LoadDataGridViewSearchUserCITest()
        {
            string searchUser = "4494524"; // TODO: Initialize to an appropriate value
            //DataTable expected = null; // TODO: Initialize to an appropriate value
            string nameUser = "Leonardo";
            DataTable actual;
            actual = UserManager.LoadDataGridViewSearchUser(searchUser);
            Assert.AreEqual(nameUser, actual.Rows[0][1].ToString());
            
            //Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for FirstName LoadDataGridViewSearchUser
        ///</summary>
        [TestMethod()]
        public void LoadDataGridViewSearchUserFirstNameTest()
        {
            string searchUser = "Leonardo"; // TODO: Initialize to an appropriate value
            //DataTable expected = null; // TODO: Initialize to an appropriate value
            string ciUser = "4494524";
            DataTable actual;
            actual = UserManager.LoadDataGridViewSearchUser(searchUser);
            Assert.AreEqual(ciUser, actual.Rows[0]["CiManager"].ToString());

            //Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for LastName LoadDataGridViewSearchUser
        ///</summary>
        [TestMethod()]
        public void LoadDataGridViewSearchUserLasttNameTest()
        {
            string searchUser = "Mejia"; // TODO: Initialize to an appropriate value
            //DataTable expected = null; // TODO: Initialize to an appropriate value
            string nameUser = "Leonardo";
            DataTable actual;
            actual = UserManager.LoadDataGridViewSearchUser(searchUser);
            Assert.AreEqual(nameUser, actual.Rows[0]["FirstName"].ToString());

            //Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for Null LoadDataGridViewSearchUser
        ///</summary>
        [TestMethod()]
        public void LoadDataGridViewSearchUserNullTest()
        {
            string searchUser = "asd"; // TODO: Initialize to an appropriate value
            //DataTable expected = null; // TODO: Initialize to an appropriate value
            string nameUser = null;
            DataTable actual;
            actual = UserManager.LoadDataGridViewSearchUser(searchUser);
            Assert.AreEqual(nameUser, actual);

            //Assert.Inconclusive("Verify the correctness of this test method.");
        }

        ///// <summary>
        /////A test for LoadDataGridViewSearchUser
        /////</summary>
        //[TestMethod()]
        //public void LoadDataGridViewSearchUserTest()
        //{
        //    string searchUser = string.Empty; // TODO: Initialize to an appropriate value
        //    DataTable expected = null; // TODO: Initialize to an appropriate value
        //    DataTable actual;
        //    actual = UserManager.LoadDataGridViewSearchUser(searchUser);
        //    Assert.AreEqual(expected, actual);
        //    //Assert.Inconclusive("Verify the correctness of this test method.");
        //}

        ///// <summary>
        /////A test for LoadDataGridViewUser
        /////</summary>
        //[TestMethod()]
        //public void LoadDataGridViewUserTest()
        //{
        //    DataTable expected = null; // TODO: Initialize to an appropriate value
        //    DataTable actual;
        //    actual = UserManager.LoadDataGridViewUser();
        //    Assert.AreEqual(expected, actual);
        //    //Assert.Inconclusive("Verify the correctness of this test method.");
        //}
    }
}
